home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Perusromppu 2
/
Perusromppu 2 - 40 suomenkielistä opetusohjelmaa.iso
/
perusr2
/
mmlab
/
keyboard.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-08-03
|
11KB
|
366 lines
{ -------------------------------------------------------------------- }
{ }
{ Copyright (c) Gävle DPC 1993 }
{ }
{ You have the right to use,reproduce, modify and distribute this file }
{ if you find it useful, provided that you agree that }
{ Gävle DPC has no warranty obligations or liability for any }
{ errors caused by the file. }
{ }
{ }
{ -------------------------------------------------------------------- }
{ 94xxxx M.E. }
{ -------------------------------------------------------------------- }
PROGRAM MML_Template;
{$IFDEF MML}
{$D+,L+}
{$ELSE}
{$D-,L-}
{$ENDIF}
{$I DEPEND.INC}
USES Strings,
WinTypes,
WinProcs,
MMSystem,
OLE,
OWindows,
MMLRun,
MMLDefs,
MMLLib,
MMLMemory,
MMLOLE,
MMLPages,
Pages; { Auto generated unit }
{$R MML.RES}
{ ------------------------------------------------------------------------ }
TYPE DemoApplication_ = OBJECT(TApplication)
CONSTRUCTOR Init(AName : PChar);
DESTRUCTOR Done; VIRTUAL;
PROCEDURE InitMainWindow; VIRTUAL;
END;
TYPE DemoWindowPtr_ = ^DemoWindow_;
DemoWindow_ = OBJECT(TWindow)
Pages : PagesPtr_;
HasTimer : Boolean;
InTimer : Boolean;
IdleStart : Longint;
Focused : Boolean;
CONSTRUCTOR Init(AParent : PWindowsObject);
DESTRUCTOR Done; VIRTUAL;
PROCEDURE SetupWindow; VIRTUAL;
FUNCTION GetClassname : PChar; VIRTUAL;
PROCEDURE GetWindowClass(VAR WndClass: TWndClass); VIRTUAL;
{ ---------------------------------------------------- }
PROCEDURE Paint(PaintDC : HDC;
VAR PaintInfo : TPaintStruct); VIRTUAL;
PROCEDURE WMLButtonDown(VAR msg : TMessage);
VIRTUAL wm_First+WM_LButtonDown;
PROCEDURE WMRButtonDown(VAR msg : TMessage);
VIRTUAL wm_First+WM_RButtonDown;
PROCEDURE WMSetCursor(VAR Msg : TMessage);
VIRTUAL wm_First+wm_SetCursor;
PROCEDURE WMTimer(VAR Msg : TMessage);
VIRTUAL wm_First+wm_Timer;
PROCEDURE WMKeyDown(VAR Msg : TMessage);
VIRTUAL wm_First+wm_KeyDown;
{ ---------------------------------------------------- }
PROCEDURE CMReleaseMemory(VAR Msg : TMessage);
VIRTUAL cm_First+cm_ReleaseMemory;
PROCEDURE SetTitle(Force : Boolean);
FUNCTION IsFocused : Boolean;
PROCEDURE BreakIdle;
FUNCTION GetIdleTime : Longint;
PROCEDURE StartExecution;
PROCEDURE StopExecution;
END;
{ ------------------------------------------------------------------------ }
FUNCTION ClientCallBack(Client : POleClient;
Notification : TOle_Notification;
OleObject : POleObject): Integer; EXPORT;
BEGIN
ClientCallBack:=1;
{
CASE Notification OF
ole_Changed,
ole_Saved,
ole_Renamed : ;
END;
}
END;
{ -------------------------------------- }
CONSTRUCTOR DemoApplication_.Init(AName : PChar);
BEGIN
@OLEClientVTbl.CallBack:=MakeProcInstance(@ClientCallBack,HInstance);
OLEClient.lpvtbl:=@OLEClientVTbl;
CFOwnerLink:=RegisterClipboardFormat('OwnerLink');
CFObjectLink:=RegisterClipboardFormat('ObjectLink');
OleRegisterClientDoc('MML','NONAME',0,OLEClientDoc);
RegisterOLE(OLEClientVtbl,OLEClient,OLEClientDoc);
INHERITED Init(AName);
END;
DESTRUCTOR DemoApplication_.Done;
BEGIN
OleRevokeClientDoc(OLEClientDoc);
FreeProcInstance(@OleClientVTbl.CallBack);
INHERITED Done;
END;
PROCEDURE DemoApplication_.InitMainWindow;
BEGIN
MainWindow:=New(DemoWindowPtr_,Init(NIL));
END;
{ -------------------------------------------------------------------------- }
CONSTRUCTOR DemoWindow_.Init(AParent : PWindowsObject);
BEGIN
INHERITED Init(AParent,PageLayout.Title);
IF (PageLayout.UseTitle) THEN
Attr.Style:=ws_Visible OR ws_Overlapped OR ws_SysMenu OR ws_Caption
ELSE
Attr.Style:=ws_Visible OR ws_PopUpWindow;
Attr.x:=0;
Attr.y:=0;
Attr.w:=PageLayout.Width;
Attr.h:=PageLayout.Height;
Pages:=CreatePages(PageLayout.BkColour);
IF (Pages=NIL) THEN
Fail;
END;
DESTRUCTOR DemoWindow_.Done;
BEGIN
StopExecution;
IF (Pages<>NIL) THEN
Dispose(Pages,Kill);
DestroyCursor(ButtonCursor);
INHERITED Done;
END;
PROCEDURE DemoWindow_.SetupWindow;
BEGIN
INHERITED SetupWindow;
MainWindow:=HWindow;
MainTask:=GetCurrentTask;
ButtonCursor:=LoadCursor(HInstance,MakeIntResource(cursor_Area));
Pages^.AllocMemory; { Load bitmaps ... }
StartExecution;
END;
FUNCTION DemoWindow_.GetClassname : PChar;
BEGIN
GetClassname:='DemoWindow';
END;
PROCEDURE DemoWindow_.GetWindowClass(VAR WndClass : TWndClass);
BEGIN
TWindow.GetWindowClass(WndClass);
WndClass.hbrBackground:=CreateSolidBrush(PageLayout.BkColour);
WndClass.HIcon:=LoadIcon(HInstance,MakeIntResource(icon_Programme));
END;
CONST FirstPaint : Boolean = True;
PROCEDURE DemoWindow_.Paint(PaintDC : HDC;
VAR PaintInfo : TPaintStruct);
BEGIN
IF (Pages<>NIL) THEN BEGIN
IF (FirstPaint) THEN BEGIN
FirstPaint:=False;
Pages^.Run(PageLayout.MouseJumps);
END ELSE
Pages^.UpdateScreen(PaintDC,@PaintInfo.RCPaint);
END;
END;
PROCEDURE DemoWindow_.WMLButtonDown(VAR Msg : TMessage);
BEGIN
IF (Pages<>NIL) THEN BEGIN
IF (NOT Pages^.MouseDown(GraphC_(Msg.LParamLo),GraphC_(Msg.LParamHi))) THEN BEGIN
IF (PageLayout.MouseJumps) AND (NOT Pages^.InWaitMode) THEN
Pages^.NextPage;
END;
BreakIdle;
END;
END;
PROCEDURE DemoWindow_.WMRButtonDown(VAR Msg : TMessage);
BEGIN
IF (Pages<>NIL) THEN BEGIN
IF (PageLayout.MouseJumps) AND (NOT Pages^.InWaitMode) THEN
Pages^.PrevPage;
BreakIdle;
END;
END;
PROCEDURE DemoWindow_.WMSetCursor(VAR Msg : TMessage);
VAR Pt : TPoint;
R : TRect;
BEGIN
BreakIdle;
GetCursorPos(Pt);
ScreenToClient(HWindow,Pt);
GetClientRect(HWindow,R);
IF (Pages<>NIL) AND (PtInRect(R,Pt)) THEN
Pages^.SetMouseCursor(Pt.x,Pt.y)
ELSE
DefWndProc(Msg);
END;
PROCEDURE DemoWindow_.WMTimer(VAR Msg : TMessage);
BEGIN
IF (NOT InTimer) THEN BEGIN
TimerUpdateMCIDevices;
SetTitle(False);
IF (Pages<>NIL) AND (IsFocused) AND (NOT FirstPaint) THEN BEGIN
IF (PageLayout.UseIdle) AND (GetIdleTime>PageLayout.IdleTime) THEN
Pages^.IdleAction(PageLayout.IdlePage)
ELSE BEGIN
Pages^.ExecuteNext;
IF (Pages^.ExecutionStopped) THEN BEGIN
StopExecution;
CloseWindow;
END;
END;
END;
END;
END;
PROCEDURE DemoWindow_.WMKeyDown(VAR Msg : TMessage);
BEGIN
IF (Msg.WParam=vk_Escape) THEN
PostMessage(HWindow,wm_SysCommand,sc_Close,0);
DefWndProc(Msg);
END;
PROCEDURE DemoWindow_.CMReleaseMemory(VAR Msg : TMessage);
BEGIN
IF (Pages<>NIL) THEN
Pages^.ReleaseMemory(GetLowMemoryLimit);
END;
PROCEDURE DemoWindow_.SetTitle(Force : Boolean);
VAR IdleLeft : Word;
Tmp : StrZ_;
Tmp2 : StrZ_;
BEGIN
IdleLeft:=Max(0,PageLayout.IdleTime-GetIdleTime);
IF (PageLayout.UseIdle) AND (IdleLeft<=10) THEN BEGIN
Str(IdleLeft,Tmp);
SetWindowText(HWindow,Tmp);
END ELSE IF (Force) OR (Focused<>IsFocused) THEN BEGIN
Focused:=IsFocused;
StrCopy(Tmp,PageLayout.Title);
IF (NOT Focused) THEN BEGIN
LoadString(HInstance,txt_Paused,Tmp2,SizeOf(Tmp2));
StrCat(Tmp,Tmp2);
END;
SetWindowText(HWindow,Tmp);
END;
END;
FUNCTION DemoWindow_.IsFocused : Boolean;
BEGIN
IsFocused:=(GetFocus=HWindow);
END;
PROCEDURE DemoWindow_.BreakIdle;
BEGIN
IF (PageLayout.UseIdle) THEN BEGIN
IF (PageLayout.IdleTime-GetIdleTime<=10) THEN BEGIN
IdleStart:=TimeGetTime;
SetTitle(True);
END ELSE
IdleStart:=TimeGetTime;
END;
END;
FUNCTION DemoWindow_.GetIdleTime : Longint; { In seconds }
VAR CurTime : Longint;
BEGIN
CurTime:=TimeGetTime;
IF (CurTime<IdleStart) THEN BEGIN
IdleStart:=CurTime;
GetIdleTime:=0;
END ELSE
GetIdleTime:=(CurTime-IdleStart) DIV 1000;
END;
PROCEDURE DemoWindow_.StartExecution;
BEGIN
IF (SetTimer(HWindow,0,100,NIL)=0) THEN
MessageBox(HWindow,'Couldn''t create timer',NIL,mb_ok)
ELSE BEGIN
HasTimer:=True;
InTimer:=False;
Focused:=False;
IdleStart:=TimeGetTime;
END;
END;
PROCEDURE DemoWindow_.StopExecution;
BEGIN
IF (HasTimer) THEN BEGIN
KillTimer(HWindow,0);
HasTimer:=False;
END;
END;
{ ---------------------------------------------------------------------- }
{ ---------------------------------------------------------------------- }
VAR Application : DemoApplication_;
BEGIN
Application.Init('');
Application.Run;
Application.Done;
END.